﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Xml;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;

[assembly: CLSCompliant(true)]
namespace PersonProject
{
    [XmlRoot, Serializable, DataContract]
    public class Person 

    {
        /// <summary>
        /// empty constructor
        /// </summary>
        public Person() : this(0, "Имя", "Фамилия", 0)
        {            
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id">unique identificator of person</param>
        public Person(int id) : this(id, "Имя", "Фамилия", 0)
        {                       
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id">unique identificator of person</param>
        /// <param name="fName">First Name of person</param>
        public Person(int id, string fName) : this(id, fName, "Фамилия", 0)
        { 
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="fName"></param>
        /// <param name="lName"></param>
        public Person(int id, string fName, string lName) : this(id, fName, lName, 0)
        { 
        }

        /// <summary>
        /// Full constructor of person
        /// </summary>
        /// <param name="id">unique identificator of person</param>
        /// <param name="fName">First Name of person</param>
        /// <param name="lName">Last Name of person</param>
        /// <param name="age">Age of person</param>
        public Person(int id, string fName, string lName, int age)
        {
            this.Id = id;
            this.FName = fName;
            this.LName = lName;
            this.Age = age;
            this.m_Contacts = new Collection<Contact>();
            this.m_Adresses = new Collection<Adress>();
            this.m_Contacts.Add(new Contact());
            this.m_Adresses.Add(new Adress());
            byte[] bb = {0,0};
            this.Image = bb;
            this.Memo = bb;
        }

        public Person Copy()
        {
            return (Person)this.MemberwiseClone();
        }


        [XmlElement, DataMember]   
        public int Id { get; set; }
        [XmlElement, DataMember]
        public string FName { get; set; }
        [XmlElement, DataMember]
        public string LName { get; set; }
        [XmlElement, DataMember]
        public int Age { get; set; }
        [XmlElement, DataMember]
        public byte[] Image { get; set; }
        [XmlElement, DataMember]
        public byte[] Memo { get; set; }
        [XmlElement(typeof(Collection<Adress>)), DataMember]
        public Collection<Adress> Adresses { 
            get 
            {
                if (m_Adresses == null)
                {
                    m_Adresses = new Collection<Adress>();
                }
                return m_Adresses; 
            } }
        [XmlElement(typeof(Collection<Contact>)), DataMember]
        public Collection<Contact> Contacts { 
            get {
                if (m_Contacts == null)
            {
                m_Contacts = new Collection<Contact>();
            }
            return m_Contacts; } }

        
        private Collection<Adress> m_Adresses;
        private Collection<Contact> m_Contacts;
    }
}
